<template>
    <div class="big_box">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item>物资管理</el-breadcrumb-item>
            <el-breadcrumb-item>资质管理</el-breadcrumb-item>
        </el-breadcrumb>
        <el-divider></el-divider>

        <el-form :model="selectfrom" ref="_selectfrom">
            <el-row :gutter="5">
                <el-col :span="3">
                    <el-input placeholder="所属权人"  v-model="selectfrom.CustodianId"></el-input>
                </el-col>
                <el-col :span="3">
                    <el-select  v-model="selectfrom.Level" placeholder="资质类型">
                        <el-option value="" label="全部"></el-option>
                        <el-option v-for="v in AllTypes" :label="v.name" :value="v.value"></el-option>
                    </el-select>
                </el-col>
                <el-col :span="3">
                    <el-input placeholder="资质编号"  v-model="selectfrom.EnterpriseNumber"></el-input>
                </el-col>
                <el-col :span="3">
                    <el-date-picker style="width: 100%" placeholder="开始时间"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    v-model="selectfrom.Start"></el-date-picker>
                </el-col>
                <el-col :span="3">
                    <el-date-picker style="width: 100%" placeholder="结束时间"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    v-model="selectfrom.End"></el-date-picker>
                </el-col>
                <el-col :span="2">
                    <el-button   icon="el-icon-search" @click="formdata"></el-button>
                </el-col>
            </el-row>
        </el-form>

        <el-row style="padding: 10px 0px">
            <el-col>
                <el-button-group>
                    <el-button class="buttongroup" type="danger" icon="el-icon-delete" @click="BatchDelete_event">批量删除</el-button>
                    <el-button class="buttongroup"  type="success" icon="el-icon-circle-plus-outline" @click="AddQualification_dialog=true">新增</el-button>
                </el-button-group>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <el-table :data="tableData" border stripe style="width: 100%"  @selection-change="SelectionChange_event">
                    <el-table-column type="selection" width="40" align="center"></el-table-column>
                    <el-table-column fixed type="index" label="序号" width="50" align="center" :index="indexMethod"></el-table-column>
                    <el-table-column fixed prop="Level" show-overflow-tooltip label="资质类型" align="center" width="120">
                        <template slot-scope="slot">
                            {{ GetTypes_name(slot.row.Level) }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="EnterpriseName" show-overflow-tooltip label="企业名称" align="center"></el-table-column>
                    <el-table-column prop="EnterpriseNumber" show-overflow-tooltip label="企业编号" align="center"></el-table-column>
                    <el-table-column prop="ReleaseDate" show-overflow-tooltip label="发证日期" align="center">
                        <template slot-scope="slot">
                            {{ PurchaseDate_conversion(slot.row.ReleaseDate) }}
                        </template>
                    </el-table-column>

                    <el-table-column fixed prop="EffectiveDate" show-overflow-tooltip label="有效期" align="center"></el-table-column>

                    <el-table-column prop="CertificationAuthority" align="center" show-overflow-tooltip label="发证机关"></el-table-column>
                    <el-table-column prop="CustodianId" align="center" show-overflow-tooltip label="所属权人"></el-table-column>
                    <el-table-column prop="Id" align="center" show-overflow-tooltip label="图片">
                        <template slot-scope="slot">
                            <el-link type="primary" :underline="false" @click="SeeImahe_event(slot.row)">相册</el-link>
                        </template>
                    </el-table-column>
                    <el-table-column prop="Remark" align="center" show-overflow-tooltip label="备注"></el-table-column>
                    <el-table-column fixed="right" label="操作" width="145" align="center">
                        <template slot-scope="scope">
                            <el-button plain @click="handleClick(scope.row)" type="primary" size="mini">编辑</el-button>
                            <el-button plain type="danger" size="mini" @click="BatchDeleteOne_event(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-col>
            <el-col :span="24">
                <div class="block">
                    <el-pagination
                            @size-change="formdata"
                            @current-change="formdata"
                            :current-page.sync="pagination.currentPage"
                            :page-sizes="pagination.pagesizes"
                            :page-size.sync="pagination.pagesize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total.sync="pagination.total">
                    </el-pagination>
                </div>
            </el-col>
        </el-row>

        <el-dialog :visible.sync="AddQualification_dialog" width="80%" title="新建资质" @close="AddQualification_close">
            <AddQualification ref="AddQualification_ref" :all-types="AllTypes"></AddQualification>
        </el-dialog>

        <el-dialog :visible.sync="UpdataQualification_dialog" width="80%" title="资质信息" @close="UpdataQualification_close">
            <UpdataQualification ref="UpdataQualification_ref" :qualification="Qualification_details" :all-types="AllTypes"></UpdataQualification>
        </el-dialog>

        <el-image-viewer v-if="imageshow"
                         :on-close="()=>{ imageshow = false}"
                         :url-list="imagelis" />

    </div>
</template>

<script>
    import * as publicjs from "/public/Scriput/Public"
    import AddQualification from "./AddQualification";
    import UpdataQualification from "./UpdataQualification";

    export default {
        name: "Qualification",
        components: {
            'AddQualification': AddQualification,
            'UpdataQualification': UpdataQualification,
            'el-image-viewer': () => import('element-ui/packages/image/src/image-viewer')
        },
        data() {
            return {
                //表格数据
                tableData: [],
                //分页数据绑定
                pagination: {
                    currentPage: 1,
                    pagesizes: [10, 20, 30, 40, 50],
                    pagesize: 10,
                    total: 100
                },
                //表格选中的数据
                SelectMore_lis: [],
                //表格查询数据
                selectfrom: {
                    EnterpriseNumber: '',
                    Level: '',
                    CustodianId: '',
                    Start: '',
                    End: '',
                },
                // 单个数据详情(用于编辑)
                Qualification_details: {},
                //添加表格的显示
                AddQualification_dialog: false,
                //编辑表格的显示
                UpdataQualification_dialog: false,
                //所有资质类型
                AllTypes: [],
                imageshow: false,
                imagelis: [],
            }
        },
        created() {
            this.AllTypes = publicjs.GetAllTypes(this.$http)
            //初始数据加载
            this.formdata()
        },
        methods: {
            //初始化表格数据加载
            formdata() {
                let loadding = this.openLoading();
                this.$http.post('Qualification/GetQualificationsDb', {
                    currentPage: this.pagination.currentPage,
                    pagesize: this.pagination.pagesize,
                    EnterpriseNumber: this.selectfrom.EnterpriseNumber,
                    Level: this.selectfrom.Level,
                    CustodianId: this.selectfrom.CustodianId,
                    StartDate: this.selectfrom.Start,
                    EndDate: this.selectfrom.End,
                }).then(res => {
                    loadding.close();
                    this.pagination.total = res.data.count
                    this.tableData = res.data.data
                }).catch(() => {
                    this.$message.error('服务器异常,请联系管理员!')
                })
            },
            //序列号
            indexMethod(index) {
                return ((this.pagination.currentPage - 1) * this.pagination.pagesize) + index + 1
            },
            //表格数据选择事件
            SelectionChange_event(value) {
                this.SelectMore_lis = value
            },
            //批量删除
            BatchDelete_event() {
                this.$confirm('你确定要删除吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消'
                }).then(() => {
                    let ids = []
                    if (this.SelectMore_lis.length > 0) {
                        this.SelectMore_lis.forEach(item => {
                            ids.push(item.Id)
                        })
                        let loadding = this.openLoading();
                        this.$http.post('Qualification/DelQualificationsDB', ids).then(res => {
                            loadding.close();
                            if (res) {
                                this.$message.success('删除成功!')
                                this.SelectMore_lis = []
                                this.formdata()
                            } else {
                                this.$message.success('删除失败,请重试!')
                            }
                        }).catch(() => {
                            this.$message.info('服务器异常,请联系管理员!')
                        })
                    } else {
                        this.$message.warning('没有选中的数据!')
                    }
                }).catch(() => {
                    this.$message.info('已取消!')
                })
            },
            //单个数据删除
            BatchDeleteOne_event(obj) {
                this.SelectMore_lis.push(obj)
                this.BatchDelete_event()
            },
            //编辑
            handleClick(obj) {
                this.Qualification_details = obj
                this.UpdataQualification_dialog = true
            },
            //创建时间转化
            PurchaseDate_conversion(val) {
                return (val.split(' '))[0]
            },
            //添加表格的关闭
            AddQualification_close() {
                this.$refs['AddQualification_ref'].formresetFields_event()
            },
            //编辑表格的关闭
            UpdataQualification_close() {
                this.$refs['UpdataQualification_ref'].formresetFields_event()
            },
            // 返回资质类型名称
            GetTypes_name(val) {
                for (let i = 0; i < this.AllTypes.length; i++) {
                    if ((this.AllTypes)[i].value == val) {
                        return (this.AllTypes)[i].name
                    }
                }
            },
            //查看图片
            SeeImahe_event(obj) {
                let path = '128,1,' + obj.Id
                this.$http.get('VehicleManagement/GetUrlDocument?url=' + path).then(res => {
                    if (res.data.length > 0) {
                        this.imageshow = true
                        this.imagelis = res.data
                    } else {
                        this.$message.warning('暂未上传图片')
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>
